/**
 * Created by qiaoshi on 2019/5/31.
 */
import React, {Component} from 'react';
import Img from './img/staffmanagement.png';
import { createPage,base } from 'nc-lightapp-front'
const {NCLoading} = base
import Ajax from 'src/hrzz/public/mobile/utils/ajax'  
import proFetch  from 'src/hrpub/common/utils/project-fetch';
import './index.less'
// 取消cssmodule写法


class Management extends Component {
    constructor() {
        super();
        this.state = {
            json:{},
            entry:0,
            totle:0,
            loading:false
        };
    }
    toThousands = (num) => {
        if (!num || isNaN(num)) {
            return 0
        } else if(num<=999999){
            let regStr = '(\d)(?=(?:\d{3})+$)'
            let reg1 = new RegExp(regStr, 'g')
          return (num).toString().replace(reg1, '$1,');
        }else{
          return '999,999+'
        }
      }
    getErrCount(url) {
        this.state.loading = true
        this.setState(this.state)
        proFetch({
            url:url,
            body:{
                appcode:'600710B0'
            },
            success:(res)=> {
                if(res.success) {
                    this.setState({
                        entry:this.toThousands(res.data.entry),
                        totle:this.toThousands(res.data.totle),
                        loading:false
                    })
                }
            }
        })

    }
    componentDidMount(){
        // window.location.hash =
        // "?&c=600710B0&p=600710B0&ar=0001Z510000000065KV7&id=0";
        this.getLanguage()
        this.getErrCount('/nccloud/hrhi/widget/PsndocWidgetAction.do')
    }

    // 获取多语
	getLanguage = async () => {
		const { MultiInit } = this.props;

		return new Promise((resolve) => {
			MultiInit.getMultiLang({
				moduleId: 'hi6007',
				domainName: 'hrhi',
				callback: (json, status, init) => {
					this.setState({
                        json:json
                    })
					resolve();
				}
			});
		});
	};
    clickHandler = (e) => {
        e.preventDefault();
        // window.open('https://workbench-daily.yyuap.com/#/service/HRPA020/HRPA020')     
    }
    reRreshPage = (e) => {
        e.preventDefault();
        e.stopPropagation();
        this.getErrCount('/nccloud/hrhi/widget/PsndocWidgetAction.do')
    }
    render() {
        const { loading } = this.state
        return (
            <div className={'sticker'} onClick={this.clickHandler}>
                 <NCLoading
                        container={this}
                        show={loading} >
                </NCLoading>
                <div className={'title'}>
                {/* 员工管理 */}
                    {this.state.json['hi6007-000283']}
                </div>
                <div className={'content'}>
                    <div className={'img'}>
                        <img src={Img}/>
                    </div>
                    <div className={'font'}>
                        <p className={'blue'}>{this.state.totle}</p>
                        {/* 在职员工数量 */}
                        <span>{this.state.json['hi6007-000284']}</span>
                    </div>
                    <div className={'font'}>
                        <p className={'orange'}>{this.state.entry}</p>
                        {/* 待入职人数 */}
                        <span>{this.state.json['hi6007-000285']}</span>
                    </div>
                </div>
                <i className={'hrfont'} onClick={this.reRreshPage}>&#xe61e;</i>
            </div>
        )
    }

}
let TestPage = createPage({appAutoFocus: false})(Management)
ReactDOM.render(<TestPage />, document.querySelector('#app'));
